package org.cycuchy.hp.data {
	
	import flash.utils.getTimer;
	
	import mx.collections.ArrayCollection;
	
	
	public class KapstelkiData implements IDatas {
		
		public var rows:uint;
		public var cols:uint;
		
		public var verticalGap:uint;
		public var horizontalGap:uint;
		
		public var imgWidth:uint;
		public var imgHeight:uint;
		public var imgInitialWidth:uint;
		public var imgInitialHeight:uint;
		
		public var kapstelki:ArrayCollection;
		
		public function get dataLength():int {
			return kapstelki.length;
		}
		
		public function get elementsOnPage():int {
			return rows * cols;
		}

//		public static function createKapstelkiData():KapstelkiData {
//			var data:KapstelkiData = new KapstelkiData();
//			data.rows = 4;
//			data.cols = 4;
//			data.verticalGap = 10;
//			data.horizontalGap = 10;
//			data.imgWidth = 150;
//			data.imgHeight = 150;
//			data.imgInitialWidth = 50;
//			data.imgInitialHeight = 50;
//			
//			var kapstelki:ArrayCollection = new ArrayCollection();
//			var kapstelek:KapstelekData;
//			for (var i:uint=1; i<=16; i++) {
//				kapstelek = new KapstelekData();
//				kapstelek.toolTipValue = "jestem kapstelkiem numer: <b>" + i + "</b>";
//				kapstelek.imgSrc = "assets/img/kapstelek.jpg" + "?x=" + getTimer();
//				kapstelki.addItem(kapstelek);				
//			}
//			
//			data.kapstelki = kapstelki; 
//			return data;
//		}
		
		public static function xml2KapstelkiData(xml:XML):KapstelkiData {
//			trace("KapstelkiData::xml2KapstelkiData xml: ", xml);
			var data:KapstelkiData = new KapstelkiData();
			data.rows = xml.@rows;
			data.cols = xml.@cols;
			data.verticalGap = xml.@verticalGap;
			data.horizontalGap = xml.@horizontalGap;
			data.imgWidth = xml.@imgWidth;
			data.imgHeight = xml.@imgHeight;
			data.imgInitialWidth = xml.@imgInitialWidth;
			data.imgInitialHeight = xml.@imgInitialHeight;

			var kaps:ArrayCollection = new ArrayCollection();
			var kap:KapstelekData;

			for each(var k:XML in xml.list.kapstelek) {
				kap = new KapstelekData();
				kap.beerName = k.@beerName;
				kap.beerCountry = k.@beerCountry;
				kap.imgSrc = k.@imgSrc + "?x=" + getTimer();
				kaps.addItem(kap);				
			}
			data.kapstelki = kaps;
			return data;			
		}
		
	}
}